<template>
  <el-dialog width="500px" :visible.sync="visible" @cancel="close">
    <el-form size="small" :model="form">
      <el-form-item label="微信号">
        <el-input v-model="form.wechatId" placeholder="请填入微信号（ID）" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :loading="loading" @click="handleSave">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { bindTester } from '@/api/wxapp'

export default {
  name: 'BindTester',
  data() {
    return {
      loading: false,
      visible: false,
      appId: '',
      reject: null,
      resolve: null,
      form: {
        wechatId: ''
      }
    }
  },
  methods: {
    show(appId) {
      return new Promise((resolve, reject) => {
        this.resolve = resolve
        this.reject = reject
        this.visible = true
        this.appId = appId
        this.form.wechatId = ''
      })
    },
    close() {
      this.visible = false
      this.resolve = null
      this.reject = null
    },
    handleSave() {
      const data = { appId: this.appId, wechatId: this.form.wechatId }
      bindTester(data).then((resp) => {
        if (resp.code === 0) {
          this.$alert('添加成功', '提示', {
            confirmButtonText: '确定',
            callback: () => {
              this.close()
            }
          })
        } else {
          this.$alert(resp.data.msg, '提示', {
            confirmButtonText: '确定',
            callback: () => {}
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
